package com.fly.estore.service.Impl;

import com.fly.estore.dao.MemberDAO;
import com.fly.estore.domain.MemberInfo;
import com.fly.estore.framework.util.CommonUtil;
import com.fly.estore.service.MemberService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Fly on 2016/4/8.
 */
@Service("MemberService")
public class MemberServiceImpl implements MemberService {

    @Autowired
    MemberDAO memberDAO;

    public int saveMemberInfo(MemberInfo memberInfo) {
        int update = 0;
        if (StringUtils.isBlank(memberInfo.getMemberId())){
            //会员Id为空，则新增会员信息
            memberInfo.setMemberId(CommonUtil.genPK());
            update = memberDAO.addMember(memberInfo);
        }
        else {
            //会员id不为空，则更新会员信息
            update = memberDAO.updateMember(memberInfo);
        }
        return update;
    }

    public int deleteById(String memberId) {
        int update = memberDAO.deleteById(memberId);
        return update;
    }

    public MemberInfo getById(String memberId) {
        MemberInfo memberInfo = null;
        memberInfo = memberDAO.getById(memberId);
        return memberInfo;
    }

    public List<MemberInfo> queryMemberList(String memberNo, String memberName, String mobile) {
        List<MemberInfo> memberList = new ArrayList<MemberInfo>();
        memberList = memberDAO.queryMemberList(memberNo, memberName, mobile);
        return  memberList;
    }

    public List<MemberInfo> queryMemberList(String query) {
        List<MemberInfo> memberList = new ArrayList<MemberInfo>();
        memberList = memberDAO.queryMemberList(query);
        return memberList;
    }

    public int getMemberCount(String date) {
        return memberDAO.getMemberCount(date);
    }
}
